<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%--获取当前时间--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ page import="java.sql.*" %>
<%@ page import="com.mysql.jdbc.StringUtils" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.HashMap" %>
<jsp:useBean id="now" class="java.util.Date" scope="page"/>
<fmt:formatDate var="nowTime" value="${now}" pattern="yyyy-MM-dd HH:mm:ss"/>
<!DOCTYPE html>
<html>

<!--导航条 start-->


<%
  request.setCharacterEncoding("utf-8");
  //state =4 简单查询 5复合条件查询
  //处理复合查询代码
Integer state = Integer.valueOf(request.getParameter("state"));
  String keyword = null;

  /*
   * 赛选条件  age indentity price gearbox keyword
   * */

String ageSelect = null;
  String identitySelect = null;
  String lowpriceSelect = null;
String gearboxSelect = null;
  String highpriceSelect = null;






  //判断查询
  String sql = "SELECT  * from car where status = 22   ";
  if(state == 5){

    keyword = request.getParameter("keyword");
     identitySelect = request.getParameter("identitySelect");
     lowpriceSelect = request.getParameter("lowpriceSelect");
     gearboxSelect =  request.getParameter("gearboxSelect") ;
     ageSelect = request.getParameter("ageSelect");
     highpriceSelect = request.getParameter("highpriceSelect");

    System.out.println("传来的所有的参数 keyword=>"+keyword);
    System.out.println("传来的所有的参数 identitySelect=>"+identitySelect);
    System.out.println("传来的所有的参数 lowpriceSelect=>"+lowpriceSelect);
    System.out.println("传来的所有的参数 gearboxSelect=>"+gearboxSelect);
    System.out.println("传来的所有的参数 ageSelect=>"+ageSelect);

     String allManySelect = "";
     if(!identitySelect.equals("all")){
       String manySelectSql = " and identity like'%"+identitySelect+"%'";
   allManySelect = allManySelect +manySelectSql;

     }

    if(!keyword.equals("all")){
      String manySelectSql = " and name like'%"+keyword+"%'";
      allManySelect = allManySelect +manySelectSql;

    }

    if(!lowpriceSelect.equals("all")){
      String manySelectSql = " and price >"+lowpriceSelect+"";
      allManySelect = allManySelect +manySelectSql;

    }
    if(!highpriceSelect.equals("all")){
      String manySelectSql = " and price <"+highpriceSelect+"";
      allManySelect = allManySelect +manySelectSql;

    }


    if(!gearboxSelect.equals("all")){
      String manySelectSql = " and gearbox="+ Integer.valueOf(gearboxSelect);
      allManySelect = allManySelect +manySelectSql;

    }

    if(!ageSelect.equals("all")){
      String manySelectSql = " and age="+ Integer.valueOf(ageSelect);
      allManySelect = allManySelect +manySelectSql;

    }


    System.out.println("多条件查询的sql===>"+allManySelect);


    if(!StringUtils.isNullOrEmpty(keyword)){
      sql = "SELECT  * from car where status =22 "+allManySelect;
    }

  }

  //jdbc:mysql

  System.out.println("执行了sql =====》"+sql);
  Class.forName("com.mysql.jdbc.Driver");//加载驱动
  Connection conn = DriverManager.getConnection("jdbc:mysql://43.142.239.28:13307/carxianyu?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=UTC","root","root");
  PreparedStatement a = conn.prepareStatement(sql);
  ResultSet rs = a.executeQuery();





%>






<head>
  <meta charset="utf-8">
  <title>车辆查询</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${ctx}/static/layui/style/admin.css" media="all">
  <link rel="stylesheet" href="${ctx}/static/layui/style/template.css" media="all">
  <script src="${ctx}/static/layui/layui.js"></script>
  <script>
    var ctx = '${ctx}/';
  </script>
</head>
<body>
<!--导航条 start-->
<jsp:include page="/head.jsp"/>
<!--导航条 start-->


<!--导航条 end-->
<jsp:include page="/banner.jsp"/>



<%--<!--导航条 end-->--%>

<%--<span>--%>

<%--  <h1>垃圾！</h1>--%>
<%--</span>--%>

<div class="layui-container layadmin-cmdlist-fluid">




    <div class="layui-row layui-col-space30">
    <!--搜索框-->

    <div class="mainTop layui-clear">
      <div class="fr">
        <form class="layui-form" action="${ctx}/carIndex.jsp?state=5" method="post">


          <div class="layui-inline" style="text-align: left;">



          <div class="layui-form-item">



              <div class="layui-input-inline">
                车品牌：<input type="text" class="layui-input dateIcon" name="identitySelect" id="identity"
                           value="all"
                           placeholder=""
                           style="width: 140px;">
              </div>
              <div class="layui-input-inline">
              最低价：<input type="text" class="layui-input dateIcon" name="lowpriceSelect" id="lowprice"
                         value="all"
                         placeholder=""
                         style="width: 140px;">

              </div>
              <div class="layui-input-inline">
                最高价：<input type="text" class="layui-input dateIcon" name="highpriceSelect" id="higgprice"
                           value="all"
                           placeholder=""
                           style="width: 140px;">


              </div>


            <div class="layui-input-inline">
             变速箱
              <select name="gearboxSelect" id="gearboxSelect" class="layui-select">

                <option value="all"  selected>全部类型</option>
                <option value="22"  >自动</option>
                <option value="11"  >手动</option>
              </select>
            </div>

            <div class="layui-input-inline">
              选择车龄
              <select name="ageSelect" id="ageSelect" class="layui-select" style="width: auto">

                <option value="all"  selected>全部车龄</option>
                <option value="1">1 年</option>
                <option value="2">2 年</option>
                <option value="3">3 年</option>
                <option value="4">4 年</option>
                <option value="5">5 年</option>
                <option value="6">6 年</option>
                <option value="7">7 年</option>
                <option value="8">8 年</option>
              </select>
            </div>

              <div class="layui-input-inline">
                车名：<input type="text" class="layui-input dateIcon" name="keyword" id="keyword"
                       value="all"
                       placeholder=""
                       style="width: 140px;">
              </div>

            <div class="layui-input-inline">
              <button type="submit" class="layui-btn layui-btn-blue"><i
                      class="layui-icon layui-icon-search"></i> 搜索
              </button>
            </div>
          </div>
          </div>

        </form>
      </div>
    </div>







<c:if test="${sessionScope.username != null}">
    <div class="layui-col-md4 layui-col-sm6">
      <div class="cmdlist-container">
        <a href="/view/back/car/carAdd.jsp">
          <img src="http://5b0988e595225.cdn.sohucs.com/images/20180514/9e79fa15efef4892b2205b0bd50f8533.png" style="width: 100%;height: 250px;">
        </a>


          <div class="cmdlist-text">
            <p class="info"> 上传车辆</p>

          </div>

      </div>
    </div>
</c:if>

    <!--商品图begin-->
    <% while(rs.next()){

      //为列表参数初始化

      String number  = rs.getString("number");
      Integer id = rs.getInt("id");
      String name = rs.getString("name");
      String images = rs.getString("images");
      String price = rs.getString("price");

      String address = rs.getString("address");
      Integer age =Integer.valueOf( rs.getString("age"));
      String createtime = rs.getString("createtime");
      String identity = rs.getString("identity");
      String phone = rs.getString("phone");
      String username = rs.getString("username");
      Integer collection =Integer.valueOf( rs.getString("collection"));
      Integer gearboxId =Integer.valueOf( rs.getString("gearbox"));

      String gearbox = null;
      if(gearboxId == 11){
        gearbox = "手动档";
      }else {
        gearbox= "自动档";
      }



      String updateUri ="state=2&id="+id+"&name="+name+"&name="+name+"&phone="+phone+"&gearbox="+gearbox+"&=identity"+identity+"&createtime"+createtime+"&collection"+collection+"&images="+images+"&age="+age+"&number="+number+"&address="+address;
      String deleteUri =  "/view/back/car/doCarExcute.jsp?state=3&id="+id;
      String detailUri = "/view/back/car/doCarExcute.jsp?id="+id+"&name="+name+"&name="+name+"&phone="+phone+"&gearbox="+gearbox+"&=identity"+identity+"&createtime"+createtime+"&collection"+collection+"&images="+images+"&age="+age+"&number="+number+"&address="+address;
    %>

      <div class="layui-col-md4 layui-col-sm6">
        <div class="cmdlist-container">

            <img src="<%=images%>" style="width: 100%;height: 250px;">

          <a href="javascript:;">
            <div class="cmdlist-text">
              <p class="info"> <%=name%></p>
              <div class="price">
                <b><span style="color: green">$:<%=price%></span></b>
                <p>作者:<%=username%></p>
                <span class="flow"><i class="layui-icon layui-icon-date"></i>
                                 <%=createtime.substring(0,10)%>
                                </span>

                <a href=" ${ctx}/view/front/car/carDetail.jsp?id=<%=id%>"
                   class="layui-btn layui-btn-normal showDetail"
                   style="display: inline-block;margin-top: 20px;"><i
                        class="layui-icon layui-icon-release"></i> 点我查看
                </a>

              </div>
            </div>
          </a>
        </div>
      </div>
    <%}%>
    <!--商品图end-->
    <div class="layui-col-md12 layui-col-sm12">
      <div id="demo0"></div>
    </div>
  </div>


</div>







  </div>

  <%--  &lt;%&ndash;引入分页代码&ndash;%&gt;--%>
  <%--  <jsp:include page="sortPage.jsp"/>--%>
</div>


<%--<!--底部区域 start-->--%>
<div class="layui-footer footer footer-index"
     style="text-align: center;background-color: rgba(0,0,0,0.8);padding: 10px;font-size: 15px;color: #eee;">
  <div class="layui-main">
    <h4>©  二手汽车平台 版权所有</h4>
    <p>
      二手汽车平台 前端页面
    </p>
  </div>
</div>

<!--底部区域 end-->
<style>
  .fl {
    float: left;
  }

  .fr {
    float: right;
  }

  .mb10 {
    margin-bottom: 10px;
  }

  .sideBlock {
    padding: 24px;
  }

  .layui-form-item .layui-input-inline {
    width: auto;
  }

  .layui-input, .layui-select, .layui-textarea {
    height: 30px;
    width: auto;
  }

  .layui-form-label {
    padding: 8px 15px;
  }

  .layui-form-switch {
    height: 34px;
    line-height: 34px;
    margin-top: 0;
    min-width: 54px;
  }

  .layui-form-switch i {
    width: 24px;
    height: 24px;
    top: 5px;
  }

  .layui-form-onswitch i {
    margin-left: -28px;
    top: 5px;
  }

  .layui-form-switch em {
    margin-left: 27px;
  }

  .layui-form-onswitch em {
    margin-left: 5px;
  }

  .layui-btn {
    height: 36px;
  }

  /*修改颜色风格-蓝色 */
  .layui-form-select dl dd.layui-this {
    background-color: #02a7f0;
  }

  .layui-btn-blue {
    background-color: #02a7f0;
  }

  .layui-form-onswitch {
    border-color: #02a7f0;
    background-color: #02a7f0;
  }

  .layui-form-radio > i:hover, .layui-form-radioed > i {
    color: #02a7f0;
  }

  .layui-form-checked[lay-skin=primary] i {
    border-color: #02a7f0;
    background-color: #02a7f0;
  }

  .layui-form-checkbox[lay-skin=primary]:hover i {
    border-color: #02a7f0;
  }
</style>


<script>
    layui.use('carousel', function () {
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#test1'
            , width: '100%' //设置容器宽度
            , arrow: 'always' //始终显示箭头
            //, height:'400px' //设置轮播图高度
            //,anim: 'updown' //切换动画方式
        });
    });
  //注意：导航 依赖 element 模块，否则无法进行功能性操作
  var $;
  var layer;
  var element;
  var form;
  layui.use(['element', 'layer', 'jquery', 'form', 'laydate', 'layedit'], function () {
    element = layui.element;
    layer = layui.layer;
    $ = layui.jquery;
    form = layui.form;
    var laydate = layui.laydate;

    //…
  });
</script>

</body>
</html>
